﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>LoginMvc: LoginMvc.cpp Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                Examples using state machines generated by StateBuilderCpp
            </h1>
            <h3>
                LoginMvc: LoginMvc.cpp Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">LoginMvc.cpp</div>  </div>
</div>
<div class="contents">
<a href="_login_mvc_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;QtCore/QObject&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;QtCore/QDir&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;QtCore/QCoreApplication&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;QsLog.h&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;QsLogDest.h&gt;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &lt;SmQtObserver.h&gt;</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;<a class="code" href="_login_mvc_8h.html">LoginMvc.h</a>&quot;</span>
<a name="l00009"></a>00009 
<a name="l00010"></a><a class="code" href="class_login_mvc.html#a1f45b4aa714832050bbd34295c409891">00010</a> <a class="code" href="class_login_mvc.html#a1f45b4aa714832050bbd34295c409891">LoginMvc::LoginMvc</a>(<span class="keywordtype">bool</span> use_gmail):
<a name="l00011"></a>00011         m_loginTimeout(10000),
<a name="l00012"></a>00012         firstTime(true)
<a name="l00013"></a>00013 {
<a name="l00014"></a>00014     <a class="code" href="class_login_mvc.html#a26ad074cf6f826b49efe0d57618459f3">logInit</a>();
<a name="l00015"></a>00015 
<a name="l00016"></a>00016     <span class="comment">//Model</span>
<a name="l00017"></a>00017     <a class="code" href="class_login_mvc.html#a95a90c5c202ead622c77035868507d0f">m_pModel</a> = use_gmail ? (<a class="code" href="class_abstract_model.html">AbstractModel</a>*)<span class="keyword">new</span> <a class="code" href="class_g_mail_model.html">GMailModel</a>() : (<a class="code" href="class_abstract_model.html">AbstractModel</a>*)<span class="keyword">new</span> <a class="code" href="class_dummy_model.html">DummyModel</a>();
<a name="l00018"></a>00018 
<a name="l00019"></a>00019     <span class="comment">//View</span>
<a name="l00020"></a>00020     <a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a> = <span class="keyword">new</span> <a class="code" href="class_my_view.html">MyView</a>();
<a name="l00021"></a>00021     <a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>-&gt;<a class="code" href="class_my_view.html#a35eb74bc962dbe7678e8f6407c81c039">welcomeText</a> = (use_gmail  ?<span class="stringliteral">&quot;Please enter your GMail user/password&quot;</span>:<span class="stringliteral">&quot;Username=user, Password=password&quot;</span>);
<a name="l00022"></a>00022 
<a name="l00023"></a>00023     <span class="comment">//State Machine</span>
<a name="l00024"></a>00024     <a class="code" href="class_login_mvc.html#a159cd30719f8509d3243527a8f3f1e24">m_pContext</a> = <span class="keyword">new</span> LoginMvcContext(*<span class="keyword">this</span>, *<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>, <span class="keyword">this</span>);
<a name="l00025"></a>00025     <a class="code" href="class_login_mvc.html#a159cd30719f8509d3243527a8f3f1e24">m_pContext</a>-&gt;SetObserver(SmQtObserver::GetInstance());
<a name="l00026"></a>00026 
<a name="l00027"></a>00027     <a class="code" href="class_login_mvc.html#a87d2c349c352f9f71a4afc2dc861bfc6">initSignalSlot</a>();
<a name="l00028"></a>00028     setCentralWidget(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>);
<a name="l00029"></a>00029 }
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="class_login_mvc.html#a245823ee215c6d32ee3fe2a56c9da233">00031</a> <a class="code" href="class_login_mvc.html#a245823ee215c6d32ee3fe2a56c9da233">LoginMvc::~LoginMvc</a>()
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033     QLOG_INFO() &lt;&lt; <span class="stringliteral">&quot;dtor&quot;</span>;
<a name="l00034"></a>00034 }
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="class_login_mvc.html#a26ad074cf6f826b49efe0d57618459f3">00036</a> <span class="keywordtype">void</span> <a class="code" href="class_login_mvc.html#a26ad074cf6f826b49efe0d57618459f3">LoginMvc::logInit</a>()
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038    QCoreApplication *pApp = QCoreApplication::instance();
<a name="l00039"></a>00039    QsLogging::Logger&amp; logger = QsLogging::Logger::instance();
<a name="l00040"></a>00040    logger.setLoggingLevel(QsLogging::TraceLevel);
<a name="l00041"></a>00041    <span class="comment">//Log to file</span>
<a name="l00042"></a>00042    <span class="keyword">const</span> QString logPath(QDir(pApp-&gt;applicationDirPath()).filePath(<span class="stringliteral">&quot;Log.txt&quot;</span>));
<a name="l00043"></a>00043    QsLogging::DestinationPtr fileDestination(
<a name="l00044"></a>00044       QsLogging::DestinationFactory::MakeFileDestination(logPath) );
<a name="l00045"></a>00045    logger.addDestination(fileDestination);
<a name="l00046"></a>00046    <span class="comment">//Log to standard output</span>
<a name="l00047"></a>00047    QsLogging::DestinationPtr debugDestination = QsLogging::DestinationFactory::MakeDebugOutputDestination();
<a name="l00048"></a>00048    logger.addDestination(debugDestination);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 
<a name="l00051"></a><a class="code" href="class_login_mvc.html#ad63b0fff1d9c266c20804e43f9277565">00051</a> <span class="keywordtype">void</span> <a class="code" href="class_login_mvc.html#ad63b0fff1d9c266c20804e43f9277565">LoginMvc::contextEnd</a>()
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053     QLOG_INFO();
<a name="l00054"></a>00054     QCoreApplication::exit(0);
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="class_login_mvc.html#a87d2c349c352f9f71a4afc2dc861bfc6">00057</a> <span class="keywordtype">void</span> <a class="code" href="class_login_mvc.html#a87d2c349c352f9f71a4afc2dc861bfc6">LoginMvc::initSignalSlot</a>()
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059     <span class="comment">//Signals from the view</span>
<a name="l00060"></a>00060     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>-&gt;usernameEdit,SIGNAL(textChanged(QString)),<span class="keyword">this</span>, SLOT(<a class="code" href="class_login_mvc.html#a6bac2139d918bfecfabd7d80614404ba">setUsername</a>(QString)));
<a name="l00061"></a>00061     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>-&gt;passwordEdit,SIGNAL(textChanged(QString)),<span class="keyword">this</span> ,SLOT(<a class="code" href="class_login_mvc.html#acb85bf0dda3fbd7ce20e8bc9e9171228">setPassword</a>(QString)));
<a name="l00062"></a>00062     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>-&gt;timeoutSlider,SIGNAL(valueChanged(<span class="keywordtype">int</span>))  ,<span class="keyword">this</span> ,SLOT(<a class="code" href="class_login_mvc.html#a08ce56f8c34448f63347e627fee1cbb8">setLoginTimeout</a>(<span class="keywordtype">int</span>)));
<a name="l00063"></a>00063 
<a name="l00064"></a>00064     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>,SIGNAL(loginIntent()),<span class="keyword">this</span>,SLOT(<a class="code" href="class_login_mvc.html#a5bcddfb319a59f74ddb86f819ac3f21e">evIntentLogin</a>()));
<a name="l00065"></a>00065     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>,SIGNAL(cancelIntent()),<span class="keyword">this</span>,SLOT(<a class="code" href="class_login_mvc.html#a7261b77a220b0e5f63b78aeffb825a57">evCancelLogin</a>()));
<a name="l00066"></a>00066     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>,SIGNAL(contIntent()),<span class="keyword">this</span>,SLOT(<a class="code" href="class_login_mvc.html#ab936dfb09fbd609249cb46b91af15459">evIntentContinue</a>()));
<a name="l00067"></a>00067     QObject::connect(<a class="code" href="class_login_mvc.html#a822a8c9fc27e024f9a4f506a997c0b9a">m_pView</a>,SIGNAL(logoutIntent()),<span class="keyword">this</span>,SLOT(<a class="code" href="class_login_mvc.html#a54f9987f4e8f29076c360c936ff8e131">evIntentLogout</a>()));
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     <span class="comment">//Signals from the model</span>
<a name="l00070"></a>00070     QObject::connect(<a class="code" href="class_login_mvc.html#a95a90c5c202ead622c77035868507d0f">m_pModel</a>,SIGNAL(loginComplete(<span class="keywordtype">bool</span>)),
<a name="l00071"></a>00071                      <span class="keyword">this</span>, SLOT(<a class="code" href="class_login_mvc.html#a55e8d0a25944d5f67f7b3e6266914541">evLoginComplete</a>(<span class="keywordtype">bool</span>)));
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="comment">//Signals from the state machine</span>
<a name="l00074"></a>00074     QObject::connect(<a class="code" href="class_login_mvc.html#a159cd30719f8509d3243527a8f3f1e24">m_pContext</a>, SIGNAL(end()), <span class="keyword">this</span>, SLOT(<a class="code" href="class_login_mvc.html#ad63b0fff1d9c266c20804e43f9277565">contextEnd</a>()));
<a name="l00075"></a>00075 }
<a name="l00076"></a>00076 
<a name="l00077"></a><a class="code" href="class_login_mvc.html#ab936dfb09fbd609249cb46b91af15459">00077</a> <span class="keywordtype">void</span> <a class="code" href="class_login_mvc.html#ab936dfb09fbd609249cb46b91af15459">LoginMvc::evIntentContinue</a>()
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079     QLOG_INFO();
<a name="l00080"></a>00080     <a class="code" href="class_login_mvc.html#a159cd30719f8509d3243527a8f3f1e24">m_pContext</a>-&gt;evIntentContinue();
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 
<a name="l00083"></a><a class="code" href="class_login_mvc.html#a2963191e772303b37528fa27ba52394c">00083</a> <span class="keywordtype">void</span> <a class="code" href="class_login_mvc.html#a2963191e772303b37528fa27ba52394c">LoginMvc::login</a>()
<a name="l00084"></a>00084 {
<a name="l00085"></a>00085     QLOG_INFO() &lt;&lt; <span class="stringliteral">&quot;username &quot;</span> &lt;&lt; <a class="code" href="class_login_mvc.html#ab3b8d0e25bea9f29874af6d0571951d7">m_username</a> &lt;&lt; <span class="stringliteral">&quot;, password &quot;</span> &lt;&lt; <a class="code" href="class_login_mvc.html#ae51d46d55a387571ac137c6187a36831">m_password</a>;
<a name="l00086"></a>00086     <a class="code" href="class_login_mvc.html#a95a90c5c202ead622c77035868507d0f">m_pModel</a>-&gt;<a class="code" href="class_abstract_model.html#aae115f9abc845a2ea0374caaf7be1acf">login</a>(<a class="code" href="class_login_mvc.html#ab3b8d0e25bea9f29874af6d0571951d7">m_username</a>, m_password);
<a name="l00087"></a>00087 }
<a name="l00088"></a><a class="code" href="class_login_mvc.html#a87ab429303da93e11764b00db15847d5">00088</a> <span class="keywordtype">void</span> <a class="code" href="class_login_mvc.html#a87ab429303da93e11764b00db15847d5">LoginMvc::start</a>()
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090     QLOG_INFO();
<a name="l00091"></a>00091     <a class="code" href="class_login_mvc.html#a159cd30719f8509d3243527a8f3f1e24">m_pContext</a>-&gt;evStart();
<a name="l00092"></a>00092 }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094 <span class="preprocessor">#include &quot;LoginMvc.moc&quot;</span>
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
